package de.shortys.myhome.api.view.components.toolbar;

import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Font;
import java.util.Observable;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.SwingConstants;

import de.shortys.myhome.api.view.event.listener.ActivationListener;

public class SubModuleToolbarItem extends AbstractToolbarItem {

	private static final long serialVersionUID = 1L;

	private String text;

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
		label.setText(text);
	}

	public void setEnabled(boolean enabled) {
		label.setEnabled(enabled);
	}

	public boolean isEnabled() {
		return label.isEnabled();
	}

	private ImageIcon icon;

	private JLabel label;

	public SubModuleToolbarItem(ImageIcon icon) {
		this(icon, null);
	}

	public SubModuleToolbarItem(ImageIcon icon, String text) {
		this.text = text;
		this.icon = icon;
		initialize();
	}

	private void initialize() {
		getContentPane().setLayout(new BorderLayout());
		getContentPane().setCursor(new Cursor(Cursor.HAND_CURSOR));
		getContentPane().setOpaque(false);

		label = new JLabel(text, icon, SwingConstants.LEFT);
		label.setFont(new Font(label.getFont().getFamily(), Font.PLAIN, label.getFont().getSize()));
	}

	public void setToolTipText(String text) {
		label.setToolTipText(text);
	}

	@Override
	public void update(Observable o, Object arg) {
		// TODO Auto-generated method stub

	}

	@Override
	protected void buildComponents() {
		getContentPane().add(label);
	}

	@Override
	public void addActivationListener(ActivationListener listener) {
		label.addMouseListener(listener);
	}

	@Override
	public void clear() {
		// TODO Auto-generated method stub

	}
}
